<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtcheckboxlist.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Tire_Journal_Dismount extends Page
{
       public $vehhidid = null;
       public $JTJavaScript1 = null;
       public $poshid = null;
       public $axlehid = null;
       public $edOdometer = null;
       public $hiddenFname = null;
       public $hiddenLname = null;
       public $cmbAcct = null;
       public $lblAcct = null;
       public $edwonohid = null;
       public $hiddenId = null;
       public $hiddentireSN = null;
       public $edVIN = null;
       public $edType = null;
       public $edDescription = null;
       public $cmbWorkedBy = null;
       public $hiddenVeh = null;
       public $hiddenTire = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $Image1 = null;
       public $memoComments = null;
       public $cmbIssuedBy = null;
       public $lblComments = null;
       public $lblIssuedBy = null;
       public $lblWorkedBy = null;
       public $edCost = null;
       public $lblCost = null;
       public $edUnits = null;
       public $lblUnits = null;
       public $RadioGroup = null;
       public $edWONo = null;
       public $lblWONo = null;
       public $chkRecord = null;
       public $lblKpa = null;
       public $edPressure = null;
       public $lblPressure = null;
       public $lblMm = null;
       public $edTread = null;
       public $lblTread = null;
       public $edWheel = null;
       public $edAxle = null;
       public $lblWheel = null;
       public $lblAxle = null;
       public $JTGroupBox1 = null;
       public $lblDescription = null;
       public $lblVin = null;
       public $edTireCost = null;
       public $lblTireCost = null;
       public $lblType = null;
       public $lblOdometer = null;
       public $dpDate = null;
       public $lblDate = null;
       public $lblBrand = null;
       public $lblId = null;
       public $lblTireId = null;
       public $JTSiteTheme1 = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here

       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here

       <?php

       }

       function btnSubmitJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
      var veh = '<?php $oki2 = $this->vehhidid->Value; echo $oki2; ?>';
      //setTimeout("window.opener.reloadFrame(veh)", 2000);
      window.opener.reloadFrame(veh);
      //setTimeout("closeIt()", 2000);
      if(navigator.appName=="Microsoft Internet Explorer") {
      this.focus();self.opener = this;self.close(); }
      else { window.open('','_parent',''); window.close(); }
       <?php

       }


       function reloadparent()
       {

       ?>
       //Add your javascript code here
       var veh = '<?php $oki = $this->hiddenVeh->Value; echo $oki; ?>';
       //setTimeout("window.opener.reloadFrame(polnum, pol)", 2000);
        window.opener.reloadFrame(veh);
       //setTimeout("closeIt()", 2000);
        if(navigator.appName=="Microsoft Internet Explorer") {
      this.focus();self.opener = this;self.close(); }
      else { window.open('','_parent',''); window.close(); }
       <?php
       }

       function chkRecordJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.getElementById('chkRecord').checked==true)
       {
       document.getElementById('edWONo').disabled=false;
       document.getElementById('edWONo').value = document.getElementById('edwonohid').value;
       //document.getElementById('Edit1').value = document.getElementById('Edit2').value;
       }
       else
       {

       document.getElementById('edWONo').disabled=true;
       document.getElementById('edWONo').value = "";
       //document.getElementById('Edit1').value = "";
       }
       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
      if(navigator.appName=="Microsoft Internet Explorer") {
      this.focus();self.opener = this;self.close(); }
      else { window.open('','_parent',''); window.close(); }
       <?php

       }

       function Tire_Journal_DismountCreate($sender, $params)
       {
       $tire = $_GET['tire_id'];
       $veh = $_GET['veh'];
       $axle = $_GET['axle'];
       $pos = $_GET['pos'];
       $this->vehhidid->Value = $veh;
       $vehtireid = $_GET['veh_tire_id'];
       $this->hiddenTire->setValue($tire);
       $this->hiddenVeh->setValue($veh);

       /*$query_vin = "select * from vehicle_tbl where vehicle_id='".$this->hiddenVeh->getValue()."'";
       $result_vin = mysql_query($query_vin)or die(mysql_error());
       $row_vin = mysql_fetch_array($result_vin);
       $this->edVIN->Text=$row_vin['VIN'];*/

       $result_vin = mysql_query("select * from vehicle_tbl where vehicle_id='".$this->hiddenVeh->getValue()."'")or die(mysql_error());
       $row_vin = mysql_fetch_array($result_vin);
       $this->edVIN->Text=$row_vin['VIN'];
       $this->edOdometer->Text=$row_vin['curr_tracking_value'];

       $this->edType->Text='dismount';

       $this->dpDate->Date = date('Y-m-d');
       $this->edTireCost->Text = "";
       $this->edAxle->Text = "";
       $this->edWheel->Text = "";
       $this->edTread->Text = "";
       $this->edPressure->Text= "";
       $this->edWONo->Text="";
       $this->edUnits->Text = "";
       $this->edCost->Text = "";
       $this->memoComments->Text = "&nbsp";
       /*
       if($vehtireid == 'L1')
       {

       }
       */
       //axle and pos
       $this->edAxle->Text = 'n/a';
       $this->edWheel->Text = 'n/a';

       $this->edWONo->Enabled=false;

       $result_journal = mysql_query("select * from tire_inventory_tbl where company_id='".$_SESSION['company_id']."' AND tire_SN ='".$this->hiddentireSN->getValue()."'") or die('SELECT JOURNAL'.mysql_error());
       $row_journal = mysql_fetch_array($result_journal);
       $this->lblId->Caption=$_GET['tire_sn'];
       $this->lblBrand->Caption=$row_journal['vendor'].$row_journal['size'].$row_journal['type'];
       $this->edDescription->Text='Dismount Tire ID/SN:'.''.$_GET['tire_sn'].''.'on VIN:'.$row_vin['VIN'].' Axle:'.$axle.' Pos:'.$pos;
       $this->edTireCost->Text = $row_journal['cost'];

       $result_tires = mysql_query("select * from company_tires_tbl where company_id='".$_SESSION['company_id']."'") or die(mysql_error());
       $row_tires = mysql_fetch_array($result_tires);
       $this->edTread->Text=$row_tires['tread'];
       $this->edPressure->Text=$row_tires['pressure'];

       $result_cost = mysql_query("select * from company_workorders_tbl where company_id='".$_SESSION['company_id']."'") or die(mysql_error());
       $row_cost = mysql_fetch_array($result_cost);
       $this->edCost->Text=$row_cost['default_charge'];

       $auto_num = $row_cost['auto_numbering'];
       if($auto_num==1)
        {
        $this->edwonohid->Value = 'auto';
        }

      $this->cmbAcct->Clear();
      $result_acct = mysql_query("select value from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' AND category='accounts'");

      while($row_acct = mysql_fetch_array($result_acct))
      {
      $this->cmbAcct->AddItem($row_acct['value'], null, $row_acct['value']);
      }

      $this->cmbIssuedBy->Clear();
      $result_issue = mysql_query("select value from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' AND category='serviced by'");

      while($row_issue = mysql_fetch_array($result_issue))
      {
      $this->cmbIssuedBy->AddItem($row_issue['value'], null, $row_issue['value']);
      }

      /*$this->cmbWorkedBy->Clear();
      $result_work = mysql_query("select value from employee_tbl where company_id='".$_SESSION['company_id']."' AND lname='".$this->hiddenLname->getValue()."' AND fname='".$this->hiddenFname->getValue()."'");

      while($row_work = mysql_fetch_array($result_work))
      {
      $this->cmbWorkedBy->AddItem($row_work['value'], null, $row_work['value']);
      } */


       }

       function btnSubmitClick($sender, $params)
       {
       if ($this->chkRecord->Checked==true)
       {
       $record ='1';
       }
       else
       {
       $record='0';
       }

       $result = mysql_query("INSERT into tire_srvcejournal_tbl (company_id,
       vehicle_id,
       tire_id,
       date,
       odometer,
       type,
       tire_cost,
       location,
       description,
       axle,
       wheel,
       tread,
       pressure,
       record_wo,
       wo_num,
       emp_vendor,
       labor_unit,
       cost_unit,
       worked_by,
       issued_by,
       acct_num,
       comments)

       VALUES('".$_SESSION['company_id']."',
       '".$this->hiddenVeh->getValue()."',
       '".$this->hiddenTire->getValue()."',
       '".$this->dpDate->Date."',
       '".$this->edOdometer->Text."',
       '".$this->edType->Text."',
       '".$this->edTireCost->Text."',
       '".$this->edVIN->Text."',
       '".$this->edDescription->Text."',
       '".$this->edAxle->Text."',
       '".$this->edWheel->Text."',
       '".$this->edTread->Text."',
       '".$this->edPressure->Text."',
       '".$record."',
       '".$this->edwonohid->getValue()."',
       '".$this->RadioGroup->getItemIndex()."',
       '".$this->edUnits->Text."',
       '".$this->edCost->Text."',
       '".$this->cmbWorkedBy->getItemIndex()."',
       '".$this->cmbIssuedBy->getItemIndex()."',
       '".$this->cmbAcct->getItemIndex()."',
       '".$this->memoComments->Text."')") or die ('INSERT TIRE JOURNAL -' . mysql_error());

       $result2 = mysql_query("UPDATE tire_inventory_tbl SET status = 0 WHERE tire_id='".$this->hiddenTire->getValue()."'") or die ('UPDATE -' . mysql_error());
       $result3 = mysql_query("UPDATE veh_tire SET is_assigned = 'no', tire_id='0' WHERE id='".$_SESSION['veh_tire_uid']."'") or die ('UPDATE -' . mysql_error());


       redirect('refresher.php?veh='.$this->vehhidid->Value);
       }






}

global $application;

global $Tire_Journal_Dismount;

//Creates the form
$Tire_Journal_Dismount=new Tire_Journal_Dismount($application);

//Read from resource file
$Tire_Journal_Dismount->loadResource(__FILE__);

//Shows the form
$Tire_Journal_Dismount->show();

?>